﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace zhihu {
    class ExportHelper {
        private static string ReplaceDivHtml(ViewInfo vi) {
            string strHtml = Properties.Resources.divHtml;
            string strRes = strHtml.Replace("@URL", vi.QuestionUrl)
                .Replace("@TITLE", vi.Question)
                .Replace("@ANSWER", vi.Answer);

            return strRes;
        }

        public static void Expore(string outPath, List<ViewInfo> lvi){
            StringBuilder sbHtmlStr = new StringBuilder();
            foreach (var vi in lvi) {
                string divHtmlStr = ExportHelper.ReplaceDivHtml(vi);
                sbHtmlStr.Append(divHtmlStr);
            }
            // string stroutHtml = Properties.Resources.exporeHtml.Replace("@ANWSERLIST", sbHtmlStr.ToString());
            string stroutHtml = Properties.Resources.templet.Replace("@ANWSERLIST", sbHtmlStr.ToString());
            
            File.WriteAllText(outPath, stroutHtml);
        }

    }
}
